﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class UI_Location_Cell : MonoBehaviour
{
    public Text Txt_CNName;
    public Text Txt_ENName;
    public Text Txt_Code;
    public GameObject Obj_FullViewCode;
    public List<GameObject> Panel_Warning;
    public Button Btn_Clicked;

    public delegate void LocationClickedDel();

    private LocationClickedDel del_Callback;
    private int m_iLocationID;
    private FLocation m_fCurrentLocation;

    // Start is called before the first frame update
    void Start()
    {
        Btn_Clicked.onClick.AddListener(OnButtonClicked);
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    public void SetLocation(FLocation location)
    {
        m_fCurrentLocation = location;

        Txt_CNName.text = location.CNName;
        Txt_ENName.text = location.ENName;
        
        if (location.LocationType == ELocationType.E_Interior)
        {
            Txt_Code.gameObject.SetActive(false);
            Obj_FullViewCode.SetActive(true);
        }
        else
        {
            Txt_Code.text = location.Code;
            Txt_Code.gameObject.SetActive(true);
            Obj_FullViewCode.SetActive(false);
        }
        
        SetStatus(location.WarningLevel);
    }

    public void SetSelect(bool bSelect)
    {
        Color color = new Color();
        if (bSelect)
        {
            color.r = 0.9529412f;
            color.g = 0.6117647f;
            color.b = 0.06666667f;
            color.a = 1;
        }
        else
        {
            color.r = 1;
            color.g = 1;
            color.b = 1;
            color.a = 1;
        }
        Txt_CNName.color = color;
        Txt_Code.color = color;
        Txt_ENName.color = color;

    }

    public void SetStatus(EWarningLevel eWarningLevel)
    {
        foreach (var item in Panel_Warning)
        {
            item.SetActive(false);
        }

        if (eWarningLevel != EWarningLevel.E_None)
        {
            for (int i = 0; i < Panel_Warning.Count; i++)
            {
                if ((i + 1) == (int)eWarningLevel)
                {
                    Panel_Warning[i].SetActive(true);
                    break;
                }
            }
        }
    }

    public void RefreshStatus()
    {
        SetStatus(m_fCurrentLocation.WarningLevel);
    }

    public void OnButtonClicked()
    {
        del_Callback();
    }

    public void SetCallback(LocationClickedDel del)
    {
        del_Callback = del;
    }

}
